<template>
    <div class="app-container">
        <div class="blovk">项目名称</div>
        <div style="margin-bottom: 15px">
            <el-input v-model="form.name" placeholder="请输入项目名称"></el-input>
        </div>

        <div class="blovk">项目描述</div>
        <div style="margin-bottom: 15px">
            <el-input v-model="form.description" placeholder="请输入项目描述"></el-input>
        </div>

        <div class="blovk">项目链接</div>
        <div style="margin-bottom: 15px">
            <el-input v-model="form.url" placeholder="请输入项目链接"></el-input>
        </div>

        <div class="blovk">github地址</div>
        <div style="margin-bottom: 15px">
            <el-input v-model="form.github" placeholder="请输入github地址"></el-input>
        </div>

        <div class="blovk">预览图</div>
        <div style="margin-bottom: 15px">
            <Upload v-model="form.thumb"></Upload>
        </div>

        <div class="blovk">排序</div>
        <div style="margin-bottom: 15px">
            <el-select v-model="form.order">
                <el-option label="1" value="1"></el-option>
                <el-option label="2" value="2"></el-option>
                <el-option label="3" value="3"></el-option>
                <el-option label="4" value="4"></el-option>
                <el-option label="5" value="5"></el-option>
            </el-select>
        </div>

        <div style="margin-top: 20px">
            <el-button type="primary" @click="addProject">添加</el-button>
        </div>
    </div>
</template>

<script>
import { addProject } from '@/api/project'
import Upload from '@/components/Upload'
export default {
    name: 'addProject',
    components: {
        Upload
    },
    data() {
        return {
            form: {
                name: '',
                description: '',
                url: '',
                github: '',
                thumb: '',
                order: 1
            }
        }
    },
    methods: {
        addProject() {
            let obj = { ...this.form }
            obj.description = obj.description.split(',')
            obj.order = parseInt(obj.order)
            addProject(obj).then(res => {
                this.$message({
                    message: '添加成功',
                    type: 'success'
                })
                this.$router.push('/projectsList')
            })
        }
    }
}
</script>

<style scoped lang="scss">

</style>
